﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace SnippetPlugin {
    class Content {
        public static string ReplaceVariables(string template, Dictionary<string, string> variableValues) {
            Regex ex = new Regex("#(?<name>[^#]+)#");
            string instance = template;

            foreach(var variable in ex.Matches(template).OfType<Match>().Where(v => v.Groups["name"].Success)) {
                string variableName = variable.Groups["name"].Value;
                string variableValue = variableValues.FirstOrDefault(kvp => kvp.Key == variableName).Value;

                instance = instance.Replace(string.Format("#{0}#", variableName), variableValue);
            }

            return instance;
        }
    }
}
